package com.gua.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.gua.common.request.BaseController;
import com.gua.common.response.AjaxResult;
import com.gua.common.response.AjaxResultEnum;
import com.gua.user.request.UserLoginParamVO;
import com.gua.user.response.LoginResultRespVO;
import com.gua.user.response.UserInfoDetailRespVO;
import com.gua.user.service.LoginService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "用户登录/登出", tags = { "用户登录/登出" })
@RestController
public class LoginController extends BaseController{

    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "登录")
    @PostMapping("/user/login")
    public AjaxResult<LoginResultRespVO> login(@RequestBody UserLoginParamVO userLoginParamVO){
    	LoginResultRespVO loginResultRespVO = loginService.login(userLoginParamVO);
        return new AjaxResult<>(AjaxResultEnum.SUCCESS.getCode(), "登录成功", loginResultRespVO);
    }
    
    @ApiOperation(value = "登录")
    @GetMapping("/user/getInfo")
    public AjaxResult<UserInfoDetailRespVO> getLoginUserInfo(){
    	UserInfoDetailRespVO userInfoDetailRespVO = loginService.getLoginUserInfo();
        return new AjaxResult<>(AjaxResultEnum.SUCCESS.getCode(), "获取成功", userInfoDetailRespVO);
    }
    
    @ApiOperation(value = "登出")
    @GetMapping("/user/logout")
    public AjaxResult<Void> logout(){
        loginService.logout();
        return new AjaxResult<>(AjaxResultEnum.SUCCESS.getCode(), "注销成功");
    }
}
